package cn.gjxblog.controller;


import cn.gjxblog.common.model.HttpResult;
import cn.gjxblog.common.model.PageCondition;
import cn.gjxblog.model.entity.Agency;
import cn.gjxblog.model.entity.User;
import cn.gjxblog.service.AgencyService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author gjx
 * @version v1.0
 * @Description
 * @date 2018/12/18 11:30
 */
@RestController
@RequestMapping("/agency")
public class AgencyController {

    @Resource
    private AgencyService agencyService;

    @PostMapping("/addAgency")
    public HttpResult addAgency(@RequestBody Agency agency) {
        agencyService.add(agency);
        return HttpResult.success();
    }

    @GetMapping("/getAgent")
    public HttpResult<User> getAgent(@RequestParam("id") String id) {
        User user = agencyService.getAgentDetail(id);
        return HttpResult.success(user);
    }

    @GetMapping("/getAgency")
    public HttpResult<Agency> getAgency(@RequestParam("id") String id) {
        Agency agency = agencyService.getAgencyDetail(id);
        return HttpResult.success(agency);
    }

    @GetMapping("/queryAgency")
    public HttpResult<List<Agency>> queryAgency() {
        List<Agency> agencies = agencyService.getAllAgency();
        return HttpResult.success(agencies);
    }

    @PostMapping("/queryAgent")
    public HttpResult<PageInfo<User>> queryAgent(@RequestBody PageCondition pageCondition){
        PageInfo<User>  agencies =  agencyService.getAgentsByCondition(pageCondition);
       return HttpResult.success(agencies);
    }


}
